<script lang="ts" setup>
import { useAppStore } from '@/stores';

const appStore = useAppStore();

const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();

const avatar = computed(
  () => '//p3-armor.byteimg.com/tos-cn-i-49unhts6dw/dfdba5317c0c20ce20e64fac803d52bc.svg~tplv-49unhts6dw-image.image',
);

const topMenu = computed(() => appStore.topMenu && appStore.menu);
const toggleDrawerMenu = inject('toggleDrawerMenu') as () => void;

function setServerMenu() {
  appStore.fetchServerMenuConfig();
  console.log(appStore.serverMenu);
}
</script>

<template>
  <div class="navbar">
    <div class="left-side">
      <a-space>
        <img alt="logo" :src="avatar" />
        <a-typography-title :style="{ margin: 0, fontSize: '18px' }" :heading="5"> Arco Pro </a-typography-title>
        <icon-menu-fold
          v-if="!topMenu && appStore.device === 'mobile'"
          class="cursor-pointer text-5"
          @click="toggleDrawerMenu"
        />
      </a-space>
    </div>
    <div class="center-side">
      <base-menu v-if="topMenu" />
    </div>
    <ul class="right-side">
      <li>
        <a-tooltip :content="isFullscreen ? '点击退出全屏模式' : '点击切换全屏模式'">
          <a-button class="nav-btn" type="outline" shape="circle" @click="toggleFullScreen">
            <template #icon>
              <icon-fullscreen-exit v-if="isFullscreen" />
              <icon-fullscreen v-else />
            </template>
          </a-button>
        </a-tooltip>
      </li>
      <li>
        <a-dropdown trigger="click">
          <a-avatar class="cursor-pointer" :size="32">
            <img alt="avatar" :src="avatar" />
          </a-avatar>
          <template #content>
            <a-doption>
              <a-space @click="setServerMenu">
                <icon-user />
                <span>切换动态路由</span>
              </a-space>
            </a-doption>
            <a-doption>
              <a-space>
                <icon-settings />
                <span>用户设置</span>
              </a-space>
            </a-doption>
          </template>
        </a-dropdown>
      </li>
    </ul>
  </div>
</template>

<style scoped lang="less">
.navbar {
  display: flex;
  justify-content: space-between;
  height: 100%;
  background-color: var(--color-bg-2);
  border-bottom: 1px solid var(--color-border);
}
.left-side {
  display: flex;
  align-items: center;
  padding-left: 20px;
}
.center-side {
  flex: 1;
}
.right-side {
  display: flex;
  padding-right: 20px;
  list-style: none;

  li {
    display: flex;
    align-items: center;
    padding: 0 10px;
  }
  a {
    color: var(--color-text-1);
    text-decoration: none;
  }
  .nav-btn {
    border-color: rgb(var(--gray-2));
    color: rgb(var(--gray-8));
    font-size: 16px;
  }
}
</style>
